package priv.hxm.speakandlisten;

import priv.hxm.speakandlisten.Listen.inner;

import com.iflytek.cloud.speech.SpeechConstant;
import com.iflytek.cloud.speech.SpeechError;
import com.iflytek.cloud.speech.SpeechSynthesizer;
import com.iflytek.cloud.speech.SpeechUtility;
import com.iflytek.cloud.speech.SynthesizerListener;

public class Speak {
	public static SynthesizerListener listener;

	/*
	 * 设计成单例
	 */
	private Speak() {

	}

	static class inner {
		static Speak mk = new Speak();
	}

	public static Speak getInstance() {
		return inner.mk;
	}

	public void shuo(String string) {
		// System.out.println("收到" + string);
		tospeech(string);
	}

	/*
	 * 文字转语音
	 */
	// 小燕（xiaoyan）、小宇（xiaoyu）、、小研（vixy）、小琪（vixq）
	// 小峰（vixf）[正常]、小梅（vixm）、小莉（vixl）、小蓉（四川话）、 小芸（vixyun）、
	// 小坤（vixk）[额。。]、小强（vixqa）[陕西话]、小莹（vixying）、 小新（vixx）、 楠楠（vinn）、老孙（vils//成熟
	private static void tospeech(String text) {
		SpeechUtility.createUtility(SpeechConstant.APPID + "=59bc97bb");//
		SpeechSynthesizer mst = SpeechSynthesizer.createSynthesizer();// 创建该对象
		mst.setParameter(SpeechConstant.VOICE_NAME, "vixq");// 设置发言人
		mst.setParameter(SpeechConstant.SPEED, "50");// 设置语速
		mst.setParameter(SpeechConstant.PITCH, "50");// 设置语调
		mst.setParameter(SpeechConstant.VOLUME, "70");// 设置音量

		SynthesizerListener synthesizerListener = new SynthesizerListener() {

			@Override
			public void onSpeakResumed() {
				// TODO Auto-generated method stub

			}

			@Override
			public void onSpeakProgress(int arg0, int arg1, int arg2) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onSpeakPaused() {
				// TODO Auto-generated method stub

			}

			@Override
			public void onSpeakBegin() {
				// TODO Auto-generated method stub

			}

			@Override
			public void onEvent(int arg0, int arg1, int arg2, int arg3,
					Object arg4, Object arg5) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onCompleted(SpeechError arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onBufferProgress(int arg0, int arg1, int arg2,
					String arg3) {
				// TODO Auto-generated method stub

			}
		};

		mst.startSpeaking(text, synthesizerListener);
	}

}
